package com.kdzy.lshy.socity_server.controller;

import com.kdzy.lshy.socity_server.service.AppVersionService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * App版本号查询
 * @author cly 2018-08-23
 *
 */

@RestController
@RequestMapping("/version")
@CrossOrigin("*")
public class AppVersionController {

    private static final Logger logger = LoggerFactory.getLogger(AppVersionController.class);

    @Autowired
    private AppVersionService appVersionService;

    /**
     * App版本号 - 查询最新版本号
     * @param param 包含当前版本号等信息
     * @return 结果集 - 是否需要更新
     */
    @RequestMapping(value = "/getVersion", method = RequestMethod.POST)
    @ApiOperation(notes = "/getVersion", httpMethod = "POST", value = "App版本号 - 查询最新版本号", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 1, message = "需要更新"),
            @ApiResponse(code = 0, message = "不需要更新"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常"),
    })
    public Object getVersion(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"oldAppVersion\": \"旧版本号\",\n" +
                            " \"socityId\": \"社区id\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产\n" +
                            "}")
                    String param, HttpServletRequest request){
        logger.info("进入《App版本号 - 查询最新版本号》getVersion()方法；入参param = " + param);
        return appVersionService.getVersion(param, request);
    }

}
